<?php
/**
 * CreateUser: zlh
 * CreateTime: 2022/4/24 10:21
 * Remark:
 */

namespace App\Models\Auth;

use App\Consts\TableConsts\TableConsts;
use App\Models\BaseModel;
use Illuminate\Support\Facades\DB;

class AuthRoleModel extends BaseModel
{
    protected $table = TableConsts::CY_ROLE_AUTH_TABLE_NAME;

    protected $primaryKey = TableConsts::CY_ROLE_AUTH_TABLE_PRIMARY_KEY;

    protected $fillable = [
        'auth_role_id',
        'auth_id',
        'role_id'
    ];

    public function getRoleAuthInfo($roleId){
        return $this
            ->withoutGlobalScopes()
            ->where('auth_role_id',$roleId)
            ->first();
    }

    public function addRoleAuthByRole($roleAuthData){
        return $this->insertGetId($roleAuthData);
    }

    public function addRoleAuthByRoleNotAuth($roleAuthData){
        return $this->withoutGlobalScopes()->insertGetId($roleAuthData);
    }

    public function saveRoleAuthByRole($roleAuthsData){
        return DB::insert('INSERT INTO cy_'.$this->table.' (`role_id`,`auth_id`,`auth_value`) VALUES '.$roleAuthsData );
    }

    public function deleteRoleAuthByRole($roleId){
        return $this
            ->withoutGlobalScopes()
            ->where('role_id',$roleId)->delete();
    }

    public function getRoleAuth($roleId)
    {
        return $this->withoutGlobalScopes()
            ->select(["*"])
            ->where('role_id',$roleId)
            ->get();
    }




}